<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="xbsj-labels" content="Earth示例"></meta>
    <title>原生Cesium API的调用</title>
    <!-- 0 引入js文件 -->
    <script src="../../XbsjEarth/XbsjEarth.js"></script>
    <style>
        html,
        body {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }
    </style>
</head>

<body>
    <div id="earthContainer" style="width: 100%; height: 100%; background: grey">
    </div>
    <script>
        var earth;
        var bgImagery;

        // 1 XE.ready()会加载Cesium.js等其他资源，注意ready()返回一个Promise对象。
        XE.ready().then(() => {
            // 1.1 创建地球
            earth = new XE.Earth('earthContainer');

            // only for Debug
            window.earth = earth;

            // 1.2 添加默认地球影像
            earth.sceneTree.root = {
                "children": [
                    {
                        "czmObject": {
                            "name": "离线影像",
                            "xbsjType": "Imagery",
                            "show": true,
                            "xbsjImageryProvider": {
                                "createTileMapServiceImageryProvider": {
                                    "url": XE.HTML.cesiumDir + 'Assets/Textures/NaturalEarthII',
                                    "fileExtension": 'jpg',
                                },
                                "type": 'createTileMapServiceImageryProvider',
                            },
                        }
                    }
                ]
            };

            // 1.3 使用原生Cesium API创建模型
            {
                // 通过earth.czm.viewer获得viewer
                var viewer = earth.czm.viewer;

                var position = Cesium.Cartesian3.fromDegrees(116.39, 39.9, 0);
                var entity = viewer.entities.add({
                    name: 'GroundVehicle',
                    position: position,
                    model: {
                        uri: '../assets/GroundVehicle/GroundVehicle.glb',
                        minimumPixelSize: 128,
                        maximumScale: 20000,
                        heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND
                    }
                });

                viewer.trackedEntity = entity;
            }

        });
    </script>
</body>

</html>